package com.ykw.parking.config;

import com.ykw.parking.mapper.UserMapper;
import com.ykw.parking.pojo1.User;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;

//自定义Realm, extends AuthorizingRealm
public class UserRealm extends AuthorizingRealm {
    @Autowired
    UserMapper userMapper;
    //授权
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal) {

        return null;
    }
    //认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken Token) throws AuthenticationException {
        UsernamePasswordToken usertoken=(UsernamePasswordToken) Token;
        User user = userMapper.queryUserbyemail(usertoken.getUsername());
        if(user==null){
            return null;
        }
        return new SimpleAuthenticationInfo("",user.getPassword(),"");
}
}
